5a2685dbe03b7059fcb412f58328f2a3cacf85ed,grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/support/ClosureEventTriggeringInterceptor.java,ClosureEventTriggeringInterceptor,performSaveOrReplicate,#Object#EntityKey#EntityPersister#boolean#Object#EventSource#boolean#,191
Before Change
false);
if (!useIdentityColumn) {
EntityInsertAction insert = new EntityInsertAction(id, values, entity, version, persister, source);
source.getActionQueue().execute(insert);
if(persister.hasCache() && !source.getPersistenceContext().wasInsertedDuringTransaction(persister, id)) {
insertVetoed=true;
}
}
if(!insertVetoed) {
cascadeAfterSave(source, persister, entity, anything);
// Very unfortunate code, but markInterceptorDirty is private. Once HHH-3904 is resolved remove this overridden method!
if (markInterceptorDirtyMethod != null) {
ReflectionUtils.invokeMethod(markInterceptorDirtyMethod, this, entity, persister, source);
After Change
* TODO: This is a horrible hack due to a bug in Hibernate's post-insert event processing (HHH-3904)
*/
@Override
protected Serializable performSaveOrReplicate(Object entity, EntityKey key, EntityPersister persister, boolean useIdentityColumn, Object anything, EventSource source, boolean requiresImmediateIdAccess) {
validate(entity, persister, source);
Serializable id = key == null ? null : key.getIdentifier();
boolean inTxn = source.getJDBCContext().isTransactionInProgress();
boolean shouldDelayIdentityInserts = !inTxn && !requiresImmediateIdAccess;
// Put a placeholder in entries, so we don't recurse back and try to save() the
// same object again. QUESTION: should this be done before onSave() is called?
// likewise, should it be done before onUpdate()?
source.getPersistenceContext().addEntry(
entity,
Status.SAVING,
null,
null,
id,
null,
LockMode.WRITE,
useIdentityColumn,
persister,
false,
false);
cascadeBeforeSave(source, persister, entity, anything);
if (useIdentityColumn && !shouldDelayIdentityInserts) {
log.trace("executing insertions");
source.getActionQueue().executeInserts();
}
Object[] values = persister.getPropertyValuesToInsert(entity, getMergeMap(anything), source);
Type[] types = persister.getPropertyTypes();
boolean substitute = substituteValuesIfNecessary(entity, id, values, persister, source);
if (persister.hasCollections()) {
substitute = substitute || visitCollectionsBeforeSave(entity, id, values, types, source);
}
if (substitute) {
persister.setPropertyValues(entity, values, source.getEntityMode());
}
TypeHelper.deepCopy(
values,
types,
persister.getPropertyUpdateability(),
values,
source);
new ForeignKeys.Nullifier(entity, false, useIdentityColumn, source)
.nullifyTransientReferences(values, types);
if (useIdentityColumn) {
EntityIdentityInsertAction insert = new EntityIdentityInsertAction(
values, entity, persister, source, shouldDelayIdentityInserts);
if (!shouldDelayIdentityInserts) {
log.debug("executing identity-insert immediately");
source.getActionQueue().execute(insert);
id = insert.getGeneratedId();
if (id != null) {
// As of HHH-3904, if the id is null the operation was vetoed so we bail
key = new EntityKey(id, persister, source.getEntityMode());
source.getPersistenceContext().checkUniqueness(key, entity);
}
}
else {
log.debug("delaying identity-insert due to no transaction in progress");
source.getActionQueue().addAction(insert);
key = insert.getDelayedEntityKey();
}
}
if (key != null) {
Object version = Versioning.getVersion(values, persister);
source.getPersistenceContext().addEntity(
entity,
(persister.isMutable() ? Status.MANAGED : Status.READ_ONLY),
values,
key,
version,
LockMode.WRITE,
useIdentityColumn,
persister,
isVersionIncrementDisabled(),
false);
if (!useIdentityColumn) {
source.getActionQueue().addAction(
new EntityInsertAction(id, values, entity, version, persister, source));
}
cascadeAfterSave(source, persister, entity, anything);
// Very unfortunate code, but markInterceptorDirty is private. Once HHH-3904 is resolved remove this overridden method!
if (markInterceptorDirtyMethod != null) {
ReflectionUtils.invokeMethod(markInterceptorDirtyMethod, this, entity, persister, source);